package _13_red_black_tree.case2;

import _13_red_black_tree.case2.RedBlackTree.Node;
import org.junit.Test;

import static _13_red_black_tree.case2.RedBlackTree.Color.BLACK;
import static _13_red_black_tree.case2.RedBlackTree.Color.RED;

/**
 * @author: mornd
 * @dateTime: 2023/6/15 - 23:14
 */
public class MyTest {
    @Test
    public void test() {
        RedBlackTree rbTree = new RedBlackTree();
        for (int i = 1; i < 20; i++) {
            rbTree.put(i, null);
        }
        System.out.println(rbTree);
    }

    @Test
    public void test2() {
        RedBlackTree rbTree = new RedBlackTree();
        Node root = new Node(4);

        Node left = new Node(2);
        Node leftL = new Node(1);
        Node leftR = new Node(3);
        root.left = left;
        left.parent = root;
        left.left = leftL;
        leftL.parent = left;
        left.right = leftR;
        leftR.parent = left;

        Node r = new Node(0);
        leftL.left = r;
        r.parent = leftL;

        root.color = BLACK;
        left.color = RED;
        leftL.color = BLACK;
        leftR.color = BLACK;
        r.color = BLACK;

        rbTree.root = root;

//        System.out.println(rbTree);
        rbTree.remove(1);
        System.out.println(rbTree);
    }

    @Test
    public void test3() {
        RedBlackTree rbTree = new RedBlackTree();
        //region Description
        Node root = new Node(8);

        Node k4 = new Node(4);
        Node k2 = new Node(2);
        Node k6 = new Node(6);
        Node k1 = new Node(1);
        Node k3 = new Node(3);
        Node k5 = new Node(5);
        Node k7 = new Node(7);

        root.left = k4;
        k4.parent = root;

        k4.left = k2;
        k4.right = k6;
        k2.parent = k4;
        k6.parent = k4;

        k2.left = k1;
        k2.right = k3;
        k1.parent = k2;
        k3.parent = k2;

        k6.left = k5;
        k6.right = k7;
        k5.parent = k6;
        k7.parent = k6;

        root.color = BLACK;
        k4.color = BLACK;
        k1.color = BLACK;
        k3.color = BLACK;
        k5.color = BLACK;
        k7.color = BLACK;

        Node k12 = new Node(12);
        Node k10 = new Node(10);
        Node k14 = new Node(14);
        Node k9 = new Node(9);
        Node k11 = new Node(11);
        Node k13 = new Node(13);
        Node k15 = new Node(15);

        root.right = k12;
        k12.parent = root;
        k12.left = k10;
        k12.right = k14;
        k10.parent = k12;
        k14.parent = k12;

        k10.left = k9;
        k10.right = k11;
        k9.parent = k10;
        k11.parent = k10;

        k14.left = k13;
        k14.right = k15;
        k13.parent = k14;
        k15.parent = k14;

        k12.color = BLACK;
        k9.color = BLACK;
        k11.color = BLACK;
        k13.color = BLACK;
        k15.color = BLACK;

        rbTree.root = root;
        //endregion

//        Node k0 = new Node(0);
//        k1.left = k0;
//        k0.parent = k1;
//        k0.color = BLACK;

        rbTree.put(0, null);
//        rbTree.remove(1);
        System.out.println(rbTree);
    }


    @Test
    public void testGet() {
        RedBlackTree rbTree = new RedBlackTree();
        for (int i = 1; i <= 1000000; i++) {
            rbTree.put(i, null);
        }
    }
}
